package com.example.henry.yindu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.henry.yindu.R;
import com.example.henry.yindu.myclass.ListViewItem;

import java.util.List;

/**
 * Created by Henry on 2018/4/6.
 */

public class ListViewItemAdapter  extends ArrayAdapter<ListViewItem> {
    public int id;
    public ListViewItemAdapter(Context context, int id1, List<ListViewItem> obj) {
        super(context, id1, obj);
        this.id = id1;

    }


    @Override
    public View getView(int postion, View view, ViewGroup parent) {
        ListViewItem item = getItem(postion);
        View v;
        ViewHolder holder;
        if(view == null){
            v = LayoutInflater.from(getContext()).inflate(id, parent, false);
            holder = new ViewHolder();
            holder.image = (ImageView)v.findViewById(R.id.item_iamge);
            holder.text = (TextView)v.findViewById(R.id.item_text);
            v.setTag(holder);
        } else {
            v = view;
            holder = (ViewHolder) v.getTag();
        }

        holder.text.setText(item.getName());
        holder.image.setImageResource(item.getImage());

        return v;
    }


    private class ViewHolder {
        ImageView image;
        TextView text;
    }
}
